﻿@model Bordspil.Models.Group


<ul id="group-menu">
    <li>@Html.ActionLink("Mínir hópar", "Index", "Group", new { userName = User.Identity.Name }, null)</li> 
    <li>@Html.ActionLink("Búa til hóp","CreateGroup", "Group")</li>
</ul>
<div id="groups">
    
@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)


       
        @Html.HiddenFor(model => model.GroupId)

        <div class="editor-label">
            Nafn á hóp
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.GroupName)
            @Html.ValidationMessageFor(model => model.GroupName)
             <input type="submit" value="Breyta Nafni hóps" class="btn btn-danger" />
        </div>


        <input type="text" id="find-user" placeholder="Leitaðu af notanda" /><button id="search-user" class="btn btn-danger">Setja í hóp</button>
        <ul class="find-result">

        </ul>


}
        <h4>Meðlimir</h4>
        <ul class="member-list">
            
        </ul>

    <button id="@Model.GroupId" class="delete-group btn btn-danger btn-large">Eyða hóp</button>
    <span id="delete-group-msg"></span>
    </div>
<script src="~/Scripts/GroupScript.js"></script>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

<script>
    $(document).ready(function () {
        $("#@Model.GroupId").click(function () {

            var id = @Model.GroupId

            $.post("/Group/DeleteGroup?id=" + id, function (data) {
                console.log(data);
                if (data === "Farin") {
                    $("#delete-group-msg").html("Hóp hefur verið eytt þér verður vísað til baka...");
                    window.location = "/Group?userName=@User.Identity.Name";
                } else {
                    $("#delete-group-msg").html("Villa kom upp, vinsamlegast reyndu aftur");
                }

            });
        });
    });

</script>

